"""借款申请客户端"""
from selenium.webdriver.common.by import By

from base.page_base import BasePage


class LoanApplication(BasePage):
    """借款申请客户端页面"""
    __quality_financial_btn = By.XPATH, '//a[contains(normalize-space(.), "品质理财")]'  # 品质理财按钮
    __personal_loan_btn = By.XPATH, '//a[text()="个人借款"]'  # 个人借款按钮
    __credit_loan_btn = By.XPATH, '//h3[text()="信用标"]/following-sibling::dl/dd[5]/a'  # 信用标立即借款按钮
    __loan_title = By.CSS_SELECTOR, '[ng-model="borrow_loan.name"]'  # 借款标题
    __loan_purpose = By.CSS_SELECTOR, '[name="use"]'  # 借款用途下拉框
    __loan_amount = By.CSS_SELECTOR, '[name="amount"]'  # 借款金额
    __loan_rate = By.CSS_SELECTOR, '[name="apr"]'  # 借款利率
    __repayment_method = By.CSS_SELECTOR, '[name="repay_type"]'  # 还款方式下拉框
    __repayment_period = By.CSS_SELECTOR, '[name="period"]'  # 还款期限下拉框
    __bid_period = By.CSS_SELECTOR, '[name="validate"]'  # 筹标期限下拉框
    __min_invest_amount = By.ID, 'tender_amount_min'  # 最低起投金额下拉框
    __max_invest_amount = By.ID, 'tender_amount_max'  # 最高可投金额下拉框
    __invest_password = By.CSS_SELECTOR, '[name="password"]'  # 借款投资密码
    __loan_description = By.ID, 'borrow_contents'  # 借款描述
    __img_editor = By.CSS_SELECTOR, '[value="编辑"]'  # 项目材料图片编辑按钮
    __add_img = By.CSS_SELECTOR, '[type="file"]'  # 项目材料图片添加按钮
    __img_submit = By.CSS_SELECTOR, '[ng-click="upfile.save()"]'  # 项目材料图片提交按钮
    __verify = By.CSS_SELECTOR, '[name="valicode"]'  # 验证码
    __submit_btn = By.CSS_SELECTOR, '[value="提交"]'  # 提交按钮
    __assert_success_text = By.CSS_SELECTOR, '.xubox_msg.xubox_text'  # 申请成功断言文本

    def hover_quality_financial(self):
        """品质理财——悬停"""
        self.base_hover(self.__quality_financial_btn)

    def click_personal_loan(self):
        """个人借款——点击"""
        self.base_click(self.__personal_loan_btn)

    def click_credit_loan(self):
        """信用标——点击"""
        self.base_switch_handle(self.__credit_loan_btn)
        self.base_click(self.__credit_loan_btn)

    def input_loan_title(self, loan_title='测试007'):
        """输入借款标题"""
        self.base_input(self.__loan_title, loan_title)

    def select_loan_purpose(self, loan_purpose='买房'):
        """选择借款用途"""
        self.base_select_list_by_test(self.__loan_purpose, loan_purpose)

    def input_loan_amount(self, loan_amount='100000'):
        """输入借款金额"""
        self.base_input(self.__loan_amount, loan_amount)

    def input_loan_rate(self, loan_rate='5.1'):
        """输入借款利率"""
        self.base_input(self.__loan_rate, loan_rate)

    def select_repayment_method(self, repayment_method='按月付息'):
        """选择还款方式"""
        self.base_select_list_by_test(self.__repayment_method, repayment_method)

    def select_repayment_period(self, repayment_period='3个月'):
        """选择还款期限"""
        self.base_select_list_by_test(self.__repayment_period, repayment_period)

    def select_bid_period(self, bid_period='30天'):
        """选择筹标期限"""
        self.base_select_list_by_test(self.__bid_period, bid_period)

    def select_min_invest_amount(self, min_invest_amount='100元'):
        """选择最低起投金额"""
        self.base_move_element_to_visible(self.__min_invest_amount)
        self.base_select_list_by_test(self.__min_invest_amount, min_invest_amount)

    def select_max_invest_amount(self, max_invest_amount='不限'):
        """选择最高可投金额"""
        self.base_select_list_by_test(self.__max_invest_amount, max_invest_amount)

    def input_invest_password(self, invest_password='123456'):
        """输入投资密码"""
        self.base_input(self.__invest_password, invest_password)

    def input_loan_description(self, loan_description='测试007'):
        """输入借款描述"""
        self.base_input(self.__loan_description, loan_description)

    def click_img_editor(self):
        """点击图片编辑按钮"""
        self.base_click(self.__img_editor)

    def add_img(self, img_path=r'E:\软件测试\传智播客_软件测试_2025\2.就业班\UI自动化项目\安享理财\img'):
        """添加图片"""
        self.base_input(self.__add_img, img_path)

    def click_img_submit(self):
        """点击图片提交按钮"""
        self.base_click(self.__img_submit)

    def input_verify(self, verify='8888'):
        """输入验证码"""
        self.base_input(self.__verify, verify)

    def click_submit_btn(self):
        """点击提交按钮"""
        self.base_click(self.__submit_btn)

    def assert_success(self):
        """提交成功断言"""
        return self.base_get_text(self.__assert_success_text)

    def loan_application_process(self):
        """借款申请流程"""
        self.hover_quality_financial()  # 品质理财——悬停
        self.click_personal_loan()  # 个人借款——点击
        self.click_credit_loan()  # 信用标——点击
        self.input_loan_title()  # 输入借款标题
        self.select_loan_purpose()  # 选择借款用途
        self.input_loan_amount()  # 输入借款金额
        self.input_loan_rate()  # 输入借款利率
        self.select_repayment_method()  # 选择还款方式
        self.select_repayment_period()  # 选择还款期限
        self.select_bid_period()  # 选择筹标期限
        self.select_min_invest_amount()  # 选择最低起投金额
        self.select_max_invest_amount()  # 选择最高可投金额
        self.input_invest_password()  # 输入投资密码
        self.input_loan_description()  # 输入借款描述
        # self.click_img_editor() # 点击图片编辑按钮
        # self.add_img() # 添加图片                                  图片上传功能有问题暂时注释掉
        # self.click_img_submit() # 点击图片提交按钮
        self.input_verify()  # 输入验证码
        self.click_submit_btn()  # 点击提交按钮
